package id.amikom.jogjabankfinder.activity;

import java.util.ArrayList;
import java.util.HashMap;

import roboguice.activity.RoboActivity;
import roboguice.inject.InjectView;
import id.amikom.jogjabankfinder.JSONHelper;
import id.amikom.jogjabankfinder.R;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class KodeBank extends RoboActivity
{

	@InjectView(R.id.list)
	ListView							listView;

	JSONHelper							jsonHelper;
	ProgressDialog						pDialog;

	ListAdapter							adapter;
	ArrayList<HashMap<String, String>>	listKodeBank;
	String								TAG_NAMA	= "nama";
	String								TAG_KODE	= "kode";

	// daftar kode bank
	// nama bank _ kodebank
	String[][]							kodebank	= new String[][]
													{
			{
			"BANK BRI", "002"
			},			
			{
			"BANK MANDIRI", "008"
			},
			{
			"BANK BNI", "009"
			},
			{
			"BANK DANAMON", "011"
			},			
			{
			"BANK BCA", "014"
			},
			{
			"BANK BII", "016"
			},
			{
			"BANK PANIN", "019"
			},			
			{
			"BANK NIAGA", "022"
			},
			{
			"BANK BUANA IND", "023"
			},
			{
			"BANK LIPPO", "026"
			},
			{
			"BANK NISP", "028"
			},
			{
			"CITIBANK N.A", "031"
			},
			{
			"BANK MULTICOR TBK", "036"
			},
			{
			"BANK ARTHA GRAHA", "037"
			},
			{
			"BANK INDONESIA", "001"
			},
			{
			"BANK MANDIRI", "008"
			},
			{
			"BNI SYARIAH", "009"
			},
			{
			"BANK DANAMON", "011"
			},
			{
			"BANK PERMATA", "013"
			},
			{
			"BANK INTERNATIONAL INDONESIA", "016"
			},
			{
			"BANK NIAGA", "022"
			},
			{
			"BANK MUAMALAT", "147"
			}

													};

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_kodebank);

		jsonHelper = new JSONHelper();
		addDataKodeBank();
		tampilData();
	}

	private void addDataKodeBank()
	{
		// TODO Auto-generated method stub
		listKodeBank = new ArrayList<HashMap<String, String>>();

		for (int row = 0; row < kodebank.length; ++row)
		{
			HashMap<String, String> map = new HashMap<String, String>();
			map.put(TAG_NAMA, kodebank[row][0]);
			map.put(TAG_KODE, kodebank[row][1]);
			listKodeBank.add(map);
		}

	}

	private void tampilData()
	{
		String[] from =
		{
				TAG_NAMA, TAG_KODE
		};
		int[] to =
		{
				R.id.txtNamaBank, R.id.txtKodeBank
		};

		adapter = new SimpleAdapter(this, listKodeBank, R.layout.kodebank_adapter,
				from, to);

		listView.setAdapter(adapter);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event)
	{
		// TODO Auto-generated method stub
		if (keyCode == KeyEvent.KEYCODE_BACK)
		{
			startActivity(new Intent(KodeBank.this, MenuUtama.class));
			finish();
		}
		return super.onKeyDown(keyCode, event);
	}

}
